class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        unordered_map<int, int> _map1;
        unordered_map<int, int> _map2;
        for (int i = 0; i < p.size(); i++)
        {
            _map1[p[i]]++;
        }
        int left = 0;
        int right = 0;
        int count = 0;
        vector<int> v;
        while (right < s.size())
        {
            _map2[s[right]]++;
            if (_map2[s[right]] <= _map1[s[right]]) count++;
            while (right - left + 1 > p.size())
            {
                if (_map2[s[left]] <= _map1[s[left]]) count--;
                _map2[s[left]]--;
                left++;
            }
            if (count == p.size())
            {
                v.push_back(left);
            }
            right++;
        }
        return v;
    }
};